package com.guqiao.mvvmlib.viewmodel;

import android.app.Application;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;

/**
 * @author jiangyao
 * @date 2019-07-19 22:37
 * @des
 */
public class BaseViewModel<T extends BaseDataModel> extends AndroidViewModel {

    /**
     * 网络加载状态的LiveData
     */
    public MutableLiveData<String> loadState;
    public T mDataModel;
    private MutableLiveData<String> data;

    public BaseViewModel(@NonNull Application application) {
        super(application);
        loadState = new MutableLiveData<>();
        mDataModel = DemoUtil.getInstance(this, 0);
    }

    public MutableLiveData<String> getData() {
        if (data == null) {
            data = new MutableLiveData<>();
            loadData();
        }
        return data;
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        if (mDataModel != null) {
            mDataModel.unDisposable();
        }
    }

    private void loadData() {
        //TODO
    }
}
